USE [Monitoring]
GO

--|--------------------------------------------------------------------------------
--| [GetUserRoleByID] - Insert Procedure Script for UserRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[GetUserRoleByID]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[GetUserRoleByID]
GO

CREATE PROCEDURE [dbo].[GetUserRoleByID]
(
	@ID int
)
AS
	SET NOCOUNT ON

	SELECT
		[ID],
		[Name]
	FROM 
UserRole
	WHERE
		[ID] = @ID
	
GO


--|--------------------------------------------------------------------------------
--| [InsertUserRole] - Insert Procedure Script for UserRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[InsertUserRole]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[InsertUserRole]
GO

CREATE PROCEDURE [dbo].[InsertUserRole]
(
	@ID int,
	@Name nvarchar(50)
)
AS
	SET NOCOUNT ON

	INSERT INTO [UserRole]
	(
		[ID],
		[Name]
	)
	VALUES
	(
		@ID,
		@Name
	)

	RETURN @@Error
GO

--|--------------------------------------------------------------------------------
--| [UpdateUserRole] - Update Procedure Script for UserRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[UpdateUserRole]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
	DROP PROCEDURE [dbo].[UpdateUserRole]
GO

CREATE PROCEDURE [dbo].[UpdateUserRole]
(
	@ID int,
	@Name nvarchar(50)
)
AS
	SET NOCOUNT ON
	
	UPDATE [UserRole]
	SET
		[ID] = @ID,
		[Name] = @Name
	WHERE 
		[ID] = @ID

	RETURN @@Error
GO

--|--------------------------------------------------------------------------------
--| [DeleteUserRole] - Update Procedure Script for UserRole
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[DeleteUserRole]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
	DROP PROCEDURE [dbo].[DeleteUserRole]
GO

CREATE PROCEDURE [dbo].[DeleteUserRole]
(
	@ID int
)
AS
	SET NOCOUNT ON

	DELETE 
	FROM   [UserRole]
	WHERE  
		[ID] = @ID

	RETURN @@Error
GO

